package com.suray.system.run.data.mysql.analyze;

import com.suray.system.run.core.ChargeInfo;
import com.suray.system.run.core.ErrorDescription;
import com.suray.system.run.data.DeviceTaskInformation;
import com.suray.system.run.data.mysql.device.entity.LowBatteryDB;
import com.suray.system.run.data.mysql.device.entity.OffLineDesDB;
import com.suray.system.run.type.DeviceType;
import com.suray.system.run.util.ExecTaskTime;

import java.util.HashMap;
import java.util.Map;

public class MonitorDataStore{
    private Map<Object, DeviceDataStore> deviceDataStores;

    public MonitorDataStore() {
        deviceDataStores = new HashMap<>();
    }

    /**
     * 获取小车数据信息
     * @param object
     * @return
     */
    public DeviceDataStore getDeviceDataStore(Object object) {
        return deviceDataStores.get(object);
    }

    /**
     * 删除设备
     * @param series
     */
    public void deleteDevice(String series) {
        deviceDataStores.remove(series);
    }

    /**
     * 新增设备数据
     * @param series
     */
    public void insertDevice(String series) {
        if (deviceDataStores.get(series) != null) {
            throw new RuntimeException("已存在序列号为" + series + "的小车数据");
        }

        deviceDataStores.put(series, new DeviceDataStore(series, DeviceType.RGV4));
    }

    /**
     * 创建异常数据
     * @param series
     * @return
     */
    public ErrorDescription createErrorDesData(String series) {
        return deviceDataStores.get(series).createErrorDesData();
    }

    /**
     * 查找当前的异常数据
     * @param series
     * @return
     */
    public ErrorDescription findErrorDesData(String series) {
        return deviceDataStores.get(series).findErrorDesData();
    }

    /**
     * 更新异常数据
     * @param series
     * @return
     */
    public boolean updateErrorDesData(String series) {
        return deviceDataStores.get(series).updateErrorDesData();
    }

    /**
     * 查找设备任务数据
     * 如果数据不存在则创建数据
     * @param series
     * @return
     */
    public DeviceTaskInformation findDeviceTaskInfoData(String series) {
        return deviceDataStores.get(series).findDeviceTaskInfoData();
    }

    /**
     * 更新设备任务信息
     * @param series
     * @return
     */
    public boolean updateDeviceTaskInfoData(String series) {
        return deviceDataStores.get(series).updateDeviceTaskInfoData();
    }

    /**
     * 查找当前设备执行的任务
     * @param series
     * @return
     */
    public ExecTaskTime findExecTaskData(String series) {
        return deviceDataStores.get(series).findExecTaskData();
    }

    /**
     * 创建当前设备执行的任务
     * @param series
     * @return
     */
    public ExecTaskTime createExecTaskData(String series) {
        return deviceDataStores.get(series).createExecTaskData();
    }

    /**
     * 更新当前设备执行的任务
     * @param series
     * @return
     */
    public boolean updateExecTaskData(String series) {
        return deviceDataStores.get(series).updateExecTaskData();
    }


    /**
     * 查找当前设备的离线信息
     * @return
     */
    public OffLineDesDB findOffLineDesData(String series) {
        return deviceDataStores.get(series).findOffLineDesData();
    }

    /**
     * 创建当前设备离线信息
     * @return
     */
    public OffLineDesDB createOffLineDesData(String series) {
        return deviceDataStores.get(series).createOffLineDesData();
    }

    /**
     * 更新当前设备离线信息
     * @return
     */
    public boolean updateOffLineDesData(String series) {
        return deviceDataStores.get(series).updateOffLineDesData();
    }

    /**
     * 查找当前设备的低电量信息
     * @return
     */
    public LowBatteryDB findLowBatteryData(String series) {
        return deviceDataStores.get(series).findLowBatteryData();
    }

    /**
     * 创建当前设备低电量信息
     * @return
     */
    public LowBatteryDB createLowBatteryData(String series) {
        return deviceDataStores.get(series).createLowBatteryData();
    }

    /**
     * 更新当前设备低电量信息
     * @return
     */
    public boolean updateLowBatteryData(String series) {
        return deviceDataStores.get(series).updateLowBatteryData();
    }

    /**
     * 查找设备当前充电信息
     * @return
     */
    public ChargeInfo findChargeInfoData(String series) {
        return deviceDataStores.get(series).findChargeInfoData();
    }

    /**
     * 创建设备当前充电信息
     * @return
     */
    public ChargeInfo createChargeInfoData(String series) {
        return deviceDataStores.get(series).createChargeInfoData();
    }

    /**
     * 更新设备当前充电信息
     * @return
     */
    public boolean updateChargeInfoData(String series) {
        return deviceDataStores.get(series).updateChargeInfoData();
    }
}
